package ee.mtiidla.tuk.data;

import java.util.LinkedHashMap;
import java.util.Map;

import ee.mtiidla.data.AgeGroup;
import ee.mtiidla.data.Athlete;
import ee.mtiidla.data.Club;
import ee.mtiidla.data.Event;
import ee.mtiidla.data.Lenex;
import ee.mtiidla.data.Meet;
import ee.mtiidla.data.Ranking;
import ee.mtiidla.data.Result;
import ee.mtiidla.data.Session;
import ee.mtiidla.utils.Utils;

/**
 * Created by Marko on 12.10.2014.
 */
public class LenexData {

	private Lenex mLenex;

	private Map<Long, Athlete> mResults;

	public LenexData(Lenex lenex) {
		mLenex = lenex;

		Meet meet = lenex.getMeets().get(0);

		Map<Long, Athlete> results = new LinkedHashMap<Long, Athlete>();

		for (Club club : meet.getClubs()) {

			for (Athlete athlete : club.getAthletes()) {

				if (!Utils.isEmpty(athlete.getResults())) {
					for (Result result : athlete.getResults()) {
						results.put(result.getResultId(), athlete);
					}
				}

			}

		}

		for (Session session : meet.getSessions()) {

			for (Event event : session.getEvents()) {

				System.out.println(event.toString());

				if (!Utils.isEmpty(event.getAgeGroups())) {
					for (AgeGroup ageGroup : event.getAgeGroups()) {
						ageGroup.setGender(event.getGender());
						System.out.println(ageGroup.toString());

						if (!Utils.isEmpty(ageGroup.getRankings())) {
							for (Ranking ranking : ageGroup.getRankings()) {
								if (ranking.getPlace() != -1) {
									System.out.println(ranking.getPlace() + ". " + results.get(ranking.getResultId()).toString());
								}
							}
						}

					}
				}

			}

		}
	}
}
